package com.example.bookkeepingelf.base.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.bookkeepingelf.R;

public class ToastUtils {

    private ToastUtils toastUtils;
    public static void showCustomToast(Context context, View view, String msg) {
        // 创建自定义 Toast
        LayoutInflater inflater = LayoutInflater.from(context);
        View layout = inflater.inflate(R.layout.custom_toast, view.findViewById(R.id.toast_layout_root));
        TextView textView = layout.findViewById(R.id.toast_text);
        textView.setText(msg);
        Toast toast = new Toast(context);
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); // 设置位置
        toast.setDuration(Toast.LENGTH_LONG); // 设置持续时间
        toast.setView(layout); // 设置自定义视图
        toast.show(); // 显示 Toast
    }
}
